package com.tedu.lingmaagent.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tedu.lingmaagent.domain.Appointment;
import com.tedu.lingmaagent.domain.Hospitals;
import com.tedu.lingmaagent.domain.Departments;
import com.tedu.lingmaagent.domain.Doctors;
import com.tedu.lingmaagent.domain.Schedules;
import com.tedu.lingmaagent.service.*;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.UUID;

@Component
public class AssistantTools {
    private final AppointmentService appointmentService;

    private final DepartmentsService departmentsService;
    private final DoctorsService doctorsService;
    private final SchedulesService schedulesService;
    private final HospitalsService hospitalsService;


    public AssistantTools(AppointmentService appointmentService,HospitalsService hospitalsService,DepartmentsService departmentsService,DoctorsService doctorsService,SchedulesService schedulesService) {
        this.appointmentService = appointmentService;
        this.hospitalsService=hospitalsService;
        this.departmentsService=departmentsService;
        this.doctorsService=doctorsService;
        this.schedulesService=schedulesService;
    }

    /*
     *预约挂号
     */
    @Tool(name="预约挂号",value="预约挂号")

    public String appointment(@P("挂号数据封装对象")Appointment appointment){
      if(appointment ==null){
          return "预约失败";
      }

        String uuid= UUID.randomUUID().toString();
      String  replace=uuid.replace("-","");
      appointment.setAppointmentId(replace);
      if(appointmentService.save(appointment)){
          return "预约成功";
      }
      return "预约失败";
    }

    @Tool(name="查询医院",value="查询医院")

    public String searchHospitals(){
        List<Hospitals> list=hospitalsService.list();
        return "医院介绍："+list;

    }

    @Tool(name="查询科室",value="查询科室")

    public String searchDepartments(){
        List<Departments> list=departmentsService.list();
        return "科室介绍："+list;
    }

    @Tool(name="查询医生",value="查询医生")

    public String searchDoctors(@P("科室名称")String deptName){
        System.out.println(deptName+"========");
        Departments department=departmentsService.getOne(new QueryWrapper<Departments>().eq("dept_name",deptName));
        List<Doctors> doctors=doctorsService.list(new QueryWrapper<Doctors>().eq("dept_id",department.getDeptId()));
        return "医生介绍："+doctors;
    }


    @Tool(name="查询排班",value="查询排班")

    public String searchSchedules(@P("医生姓名")String doctorName){
        System.out.println("===="+doctorName);
        Doctors doctors= doctorsService.getOne(new QueryWrapper<Doctors>().eq("doctor_name",doctorName));
        List<Schedules> schedules=schedulesService.list(new QueryWrapper<Schedules>().eq("doctor_id",doctors.getDoctorId()));

        return "医生展示"+schedules;
    }



}
